package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();)
        {
            Statement statement = connection.createStatement();
            String sql="select t.name,t.gender,c.name,c.floor "+
                    "from teacher t,class c " +
                    "where t.id=c.teacher_id " +
                    "and t.name='王克晶'";
            ResultSet rs=statement.executeQuery(sql);
            while(rs.next()){
                String name=rs.getString("name");
                String gender=rs.getString("gender");
                String className=rs.getString("name");
                int floor=rs.getInt("floor");
                System.out.println("{"+name+","+gender+","+className+","+floor+"}");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
